//
//  UIImage+NYExtension.m
//  BS
//
//  Created by neal on 15/8/16.
//  Copyright (c) 2015年 Neal. All rights reserved.
//

#import "UIImage+NYExtension.h"

@implementation UIImage (NYExtension)
/**
 *  生成一张圆角图片
 */
- (instancetype)clipImage
{
    UIGraphicsBeginImageContext(self.size);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
    
    CGContextAddEllipseInRect(ctx, rect);
    
    CGContextClip(ctx);
    
    [self drawInRect:rect];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
}

+ (instancetype)stretchableImageWithImageName:(NSString *)imagename
{
    UIImage *image = [UIImage imageNamed:imagename];
    image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
    return image;
}
@end
